package com.newworld.basketballfire.main.dao;

import com.newworld.basketballfire.main.bean.UserListParam;
import com.newworld.basketballfire.main.dao.mapper.DuesMapper;
import com.newworld.basketballfire.main.dao.mapper.UserMapper;
import com.newworld.basketballfire.service.model.Dues;
import com.newworld.basketballfire.service.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by George on 2019/3/3.
 * UserDao
 */
@Component
public class UserDao {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private DuesMapper duesMapper;

    @Transactional
    public void createUser(User user, Dues dues) {
        userMapper.createUser(user);
        if (dues != null) {
            duesMapper.addDues(dues);
        }
    }

    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    public User getUser(String id) {
        return userMapper.getUser(id);
    }

    public List<User> getUserList(UserListParam userListParam) {
        return userMapper.getUserList(userListParam);
    }

    public int getUserListCount(UserListParam userListParam) {
        return userMapper.getUserListCount(userListParam);
    }

    public List<User> getUsersByIds(List<String> ids) {
        return userMapper.getUsersByIds(ids);
    }
}
